package com.lkd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.VmTypeDto;
import com.lkd.entity.VmType;
import com.lkd.mapper.VmTypeMapper;
import com.lkd.result.PageBean;
import com.lkd.service.VmTypeService;
import com.lkd.vo.VmTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VmTypeServiceImpl implements VmTypeService {

    @Autowired
    private VmTypeMapper vmTypeMapper;

    @Override
    public VmTypeVo selectByNodeId(Long nodeId) {
        return vmTypeMapper.selectByNodeId(nodeId);
    }

    @Override
    public PageBean<VmTypeVo> findByPage(Integer pageIndex, Integer pageSize, String name) {

        PageHelper.startPage(pageIndex,pageSize);
        List<VmTypeVo> voList = vmTypeMapper.selectByPage(name);
        Page page = (Page) voList;
        return new PageBean(pageIndex, pageSize, (long) page.getPages(), page.getTotal(), page.getResult());
    }

    @Override
    public void save(VmTypeDto dto) {
//        对象属性拷贝
        VmType vmType = BeanUtil.toBean(dto, VmType.class);
        vmTypeMapper.insert(vmType);
    }

    @Override
    public void update(VmTypeDto dto) {
//        对象属性拷贝
        VmType vmType = BeanUtil.toBean(dto, VmType.class);
        vmTypeMapper.updateById(vmType);
    }

    @Override
    public void delete(Integer typeId) {
        vmTypeMapper.deleteById(typeId);
    }

    @Override
    public VmTypeVo selectByInnerCode(String innerCode) {
        return vmTypeMapper.selectByInnerCode(innerCode);
    }
}
